/**
 * @author joshua
 */
joshua.util.FileForm=Ext.extend(Ext.Window,{
	 title:'Cambiar imagen para mostrar',
	 iconCls: 'imagen',
//title:'Foto',
	//iconCls :'usuario',
    layout: 'fit',
    width: 380,
    autoHeight: true,
    modal:true,								  
    autoScroll:true,
    maximizable:false,
    draggable:false,
    resizable:false,
    closeAction:'hide',
    plain:true,
	
	 initComponent:function(){

		this.form= new Ext.form.FormPanel({
	        fileUpload: true,
	        width: 450,
	        frame: true,					       
	        autoHeight: true,
	        bodyStyle: 'padding: 10px 10px 0 10px;',
	        labelWidth: 50,
	        defaults: {
	            anchor: '91%',
	            allowBlank: false,
	            msgTarget: 'side'
	        },
	        items: [{
	            xtype: 'fileuploadfield',					           
	            emptyText: 'Elige una foto',
	            fieldLabel: 'Foto',
	            name: 'txt_foto',
				width:200,
	            buttonCfg: {
					text:' ',
	                iconCls: 'imagen'
	            }
	        }]
		});

		var config={
			items:this.form,
			buttons:[{
				text:'<b>Guardar</b>',	
				iconCls:'save',
				scope:this,
				handler: function(){
					this.guardarForm();
				}
			},{
				text:'<b>Cancelar</b>',
				iconCls:'delete',
				scope:this,
				handler:function(){
					this.hide();
				}
			}]
		};//fin config

		Ext.apply(this,Ext.apply(this.initialConfig,config));		
			
		joshua.util.FileForm.superclass.initComponent.apply(this,arguments);
 	},
 	
 	onRender:function(){
 		joshua.util.FileForm.superclass.onRender.apply(this,arguments);
 	},
 	
	guardarForm:function(o){
		//establecemos el md5
		if (this.form.getForm().isValid()) {
			var w=this;
			this.form.getForm().submit({
				url:"Servicios/s.php",
				scope:this,
				params:{
					cmd:'inFile',
					className:'Usuario'
				},
				success: function(fp, o){
					document.getElementById('avatar_usr').src="img/avatars/"+o.result.name;
	                        //console.info('Processed file '+o.result.name+ ' on the server');
	                        this.hide();
	            }, 
				waitMsg:'Guardando...'
			});
		}else
			joshua.funciones.alert('aviso','Aviso',"Faltan datos por completar o algunos no son validos");
	
 	}
});
